//
//  MSAreaViewTableVC.m
//  SocietySale
//
//  Created by Mike on 16/11/4.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSAreaViewTableVC.h"
#import "MSAreaCell.h"

@interface MSAreaViewTableVC ()

@end

@implementation MSAreaViewTableVC

- (void)resetState{
    for (int i = 0; i<self.stateArray.count; i++) {
        NSMutableArray *tempArray = [self.stateArray objectAtIndex:i];
        for (int j = 0;j<tempArray.count; j++ ) {
            [tempArray replaceObjectAtIndex:j withObject:@"NO"];
        }
    }
    [self.tableView reloadData];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellId = @"cellId";
    MSAreaCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[MSAreaCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.stateArray = self.stateArray[indexPath.row];
    cell.dict = self.dataArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = self.dataArray[indexPath.row];
    NSArray *countArray = [[dict allValues] objectAtIndex:0];
    if (countArray.count < 4) {
        return 45;
    }
    if (3<countArray.count && countArray.count < 7) {
        return 85;
    }
    if (6<countArray.count && countArray.count < 10) {
        return 125;
    }

    return 165;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 25)];
    headerView.backgroundColor = kDefaultViewBackgroundColor;
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 25;
}

@end
